#include "workdll.h"
#include <QDir>
#include<QMessageBox>
bool workDll::GetDll(QList<QString> &QLib)
{
    QList<QString> dll;
    QList<QList<QString> >DN;
    QDir dir;
    QString Path=QDir::currentPath();
    dir.cd(Path);
     QStringList filters;
          filters << "*.dll";
          dir.setNameFilters(filters);
     QFileInfoList lst = dir.entryInfoList();
     for (int i = 0; i < lst.size(); ++i)
     {         QFileInfo fileInfo = lst.at(i);
         dll.append(fileInfo.fileName());
         QString FileName=dll.value(i);

         if ( FileName.lastIndexOf("dist_")>=0)
         {
//             QString d=QDir::currentPath()+FileName ;
             QString d = FileName ;
             QLib.append(d);
     }
     }
     return 0;
}
bool workDll::GetParams(int Id,QList<Parameters> &Params)
{
 QMessageBox ss;
    bool Error;
    QList<QString> Dll;
    GetDll(Dll);
    QLibrary lib_Dist(Dll.value(Id));
    if (!lib_Dist.load()) ss.setText(lib_Dist.errorString());
    else ss.setText("OK");
    //ss.exec();
    typedef bool (*Param)(QList<Parameters> &);
    Param Get_Params= (Param) lib_Dist.resolve("GetParams");
      if (!Get_Params) {
          ss.setText("func Get_Params err");
         // ss.exec();
          return 1;
      }
      Error=Get_Params(Params);
      return Error;
}
bool workDll::GetDist(int Id,QList<Doc> &Docs, QVector<double> Params, QVector<QVector<double> > & Result)
{
    QMessageBox ss;
       bool Error;
       QList<QString> Dll;
       GetDll(Dll);
       QLibrary lib_Dist(Dll.value(Id));
       if (!lib_Dist.load()) ss.setText(lib_Dist.errorString());
       else ss.setText("OK");
      // ss.exec();
    typedef bool (*Dist)(const QList<Doc> &, QVector<double> , QVector<QVector<double> > &);
    Dist Get_Dist= (Dist) lib_Dist.resolve("GetDist");
      if (!Get_Dist) {
          ss.setText("func GetDist err");
          ss.exec();
          return 1;
      }
      Error=Get_Dist(Docs,Params,Result);
      return Error;
}

